<?php

/**
 * 添加这些import语句
 * 逻辑操作
 * @author Shaun
 */

namespace Member\Model;

use Utility\Log\Logger;
use Utility\ServiceLocator\ServiceLocator;
use Zend\InputFilter\InputFilter;
use Zend\InputFilter\InputFilterAwareInterface;
use Zend\InputFilter\InputFilterInterface;

class AdminModel implements InputFilterAwareInterface {

    protected $userid;      //id
    protected $username;    //用户名
    protected $password;    //密码
    protected $email;       //邮箱
    protected $phone;       //手机
    protected $image;       //头像
    protected $nickname;    //昵称
    protected $last_name;   //姓氏
    protected $first_name;  //名字
    protected $address;     //地址
    protected $url;         //个人主页
    protected $inputFilter;

    //重写接口方法

    public function setInputFilter(InputFilterInterface $inputFilter) {
        throw new \Exception("Not used");
    }

//重写接口方法
    public function getInputFilter() {
        if (!$this->inputFilter) {
            $inputFilter = new InputFilter();
            $inputFilter->add(array(
                'name' => 'username',
                'required' => true,
                'filters' => array(
                    array('name' => 'StripTags'),
                    array('name' => 'StringTrim'),
                ),
                'validators' => array(
                    array(
                        'name' => 'StringLength',
                        'options' => array(
                            'encoding' => 'UTF-8',
                            'min' => 4,
                            'max' => 100,
                        ),
                    ),
                ),
                'error_message' => ' 用户名必须填写!',
            ));

            $inputFilter->add(array(
                'name' => 'password',
                'required' => true,
                'filters' => array(
                    array('name' => 'StripTags'),
                    array('name' => 'StringTrim'),
                ),
                'validators' => array(
                    array(
                        'name' => 'StringLength',
                        'options' => array(
                            'encoding' => 'UTF-8',
                            'min' => 6,
                            'max' => 100,
                        ),
                    ),
                ),
                'error_message' => '密码必须填写!',
            ));
            $this->inputFilter = $inputFilter;
        }

        return $this->inputFilter;
    }

    //交互阵列
    public function exchangeArray($data) {
        $this->id = (isset($data['id'])) ? $data['id'] : null;
        $this->username = (isset($data['username'])) ? $data['username'] : null;
        $this->password = (isset($data['password'])) ? $data['password'] : null;
        $this->email = (isset($data['email'])) ? $data['email'] : null;
        $this->phone = (isset($data['phone'])) ? $data['phone'] : null;
        $this->image = (isset($data['image'])) ? $data['image'] : null;
        $this->nickname = (isset($data['nickname'])) ? $data['nickname'] : null;
        $this->last_name = (isset($data['last_name'])) ? $data['last_name'] : null;
        $this->first_name = (isset($data['first_name'])) ? $data['first_name'] : null;
        $this->address = (isset($data['address'])) ? $data['address'] : null;
        $this->url = (isset($data['url'])) ? $data['url'] : null;
    }

    //获取所有参数
    public function toArray() {
        $array['id'] = $this->id;
        $array['username'] = $this->username;
        $array['password'] = $this->password;
        $array['email'] = $this->email;
        $array['phone'] = $this->phone;
        $array['image'] = $this->image;
        $array['nickname'] = $this->nickname;
        $array['last_name'] = $this->last_name;
        $array['first_name'] = $this->first_name;
        $array['address'] = $this->address;
        $array['url'] = $this->url;
        return $array;
    }

}
